<template>
	<page-meta :page-style="'overflow:' + (show ? 'hidden' : 'visible')"></page-meta>
	<view class="param-contents">
		<h5 class="param-title">{{ paramTitle }}</h5>
		<!-- 仓控参数查询 -->
		<view v-if="type == 1">
			<view class="bin-card">
				<view class="bin-one" v-for="(one, index) in Number(binNum)" :key="index">
					<view class="bin-border" @click="binPopup(index,2)">{{ index + 1 }}号仓</view>
				</view>
			</view>
		</view>
		<!-- 主控参数查询 -->
		<view v-else-if="type==0">
			<view class="param-one">
				<text>软件最小版本</text>
				<text>{{ versionInfo.param1 }}</text>
			</view>
			<view class="param-one">
				<text>软件次版本</text>
				<text>{{ versionInfo.param2 }}</text>
			</view>
			<view class="param-one">
				<text>软件主版本</text>
				<text>{{ versionInfo.param3 }}</text>
			</view>
			<view class="param-one">
				<text>硬件次版本号</text>
				<text>{{ versionInfo.param4 }}</text>
			</view>
			<view class="param-one">
				<text>硬件主版本号</text>
				<text>{{ versionInfo.param5 }}</text>
			</view>
		</view>
		<!-- 操作按钮 -->
		<view class="operate_btns" v-if="type == 0">
			<u-button type="primary" size="medium" class="set_btn" @click="isRefresh">查询</u-button>
		</view>
		<!-- 检测单元 -->
		<view v-else-if="type==2">
			<view class="bin-card">
				<view class="bin-one box-one" v-for="(one,index) in comCabinNum" :key="index" :is-shadow="false">
					<view class="bin-border" @click="binPopup(index,1)">检测单元{{index+1}}</view>
				</view>
			</view>
		</view>
		<!-- 柜控电源 -->
		<view v-else-if="type==3">
			<view class="bin-card">
				<view class="bin-one box-one" v-for="(one,index) in comCabinNum" :key="index" :is-shadow="false">
					<view class="bin-border" @click="binPopup(index,3)">柜控电源{{index+1}}</view>
				</view>
			</view>
		</view>
		<!-- 整流电源 -->
		<view v-else-if="type==4">
			<view class="bin-card">
				<view class="bin-one box-one" v-for="(one,index) in comCabinNum*3" :key="index" :is-shadow="false">
					<view class="bin-border" @click="binPopup(index,4)">整流电源{{index+1}}</view>
				</view>
			</view>
		</view>
		<!-- 充电电源 -->
		<view v-else-if="type==5">
			<view class="bin-card">
				<view class="bin-one box-one" v-for="(one,index) in Number(binNum)" :key="index" :is-shadow="false">
					<view class="bin-border" @click="binPopup(index,7)">充电电源{{index+1}}</view>
				</view>
			</view>
		</view>
		<!-- 电池 -->
		<view v-else-if="type==6">
			<view class="bin-card">
				<view class="bin-one" v-for="(one,index) in Number(binNum)" :key="index" :is-shadow="false">
					<view class="bin-border" @click="binPopup(index,5)">电池{{index+1}}</view>
				</view>
			</view>
		</view>
		<!-- 详情 弹框 -->
		<uni-popup ref="binpopup" type="center" class="bin_popup" :animation="false" :is-mask-click="false">
			<view class="alertbox binpopbox">
				<uni-icons class="closeempty" type="closeempty" size="30" color="#6A6A6A"
					@click="closeBinpopup('binpopup')"></uni-icons>
				<view class="bin_left"> {{dgMessage}} </view>
				<view class="param-one">
					<text>软件最小版本</text>
					<text>{{ versionInfo.param1 }}</text>
				</view>
				<view class="param-one">
					<text>软件次版本</text>
					<text>{{ versionInfo.param2 }}</text>
				</view>
				<view class="param-one">
					<text>软件主版本</text>
					<text>{{ versionInfo.param3 }}</text>
				</view>
				<view class="param-one">
					<text>硬件次版本号</text>
					<text>{{ versionInfo.param4 }}</text>
				</view>
				<view class="param-one">
					<text>硬件主版本号</text>
					<text>{{ versionInfo.param5 }}</text>
				</view>

				<!-- 操作按钮 -->
				<view class="operate_btns">
					<u-button type="primary" size="medium" class="set_btn" @click="isRefresh(currentIndex)">读取</u-button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		DataGet,
		ab2hex,
		hexCharCodeToStr,
		arrayToBuffer,
	} from "@/utils/index.js";
	import versionjs from "./version.js";
	export default {
		mixins: [versionjs],
		data() {
			return {
				type: 0, //参数类型
				paramTitle: "", //参数模块名称
				binNum: 0, //仓个数
				currentIndex: null, //当前仓号
				show: false,
				command: null, //命令字
				deviceInfo: {}, //设备信息
				dgMessage: "", //检测状态提示信息

				versionInfo: {
					param1: "",
					param2: "",
					param3: "",
					param4: "",
					param5: "",
				},
			};
		},
		computed: {
			// 柜控电源数量
			comCabinNum() {
				if (Number(this.binNum) < 24) {
					return 1;
				} else if (Number(this.binNum) >= 24 && Number(this.binNum) < 36) {
					return 2;
				} else {
					return 3;
				}
			},
		},
		onLoad(e) {
			this.deviceInfo = JSON.parse(decodeURIComponent(e.deviceInfo));
			this.type = e.type;
			this.binNum = e.binNum;
			switch (this.type) {
				case "0":
					this.paramTitle = "主控单元";
					this.command = 0;
					break;
				case "1":
					this.paramTitle = "仓控单元";
					this.command = 2;
					break;
				case "2":
					this.paramTitle = "检测单元";
					this.command = 1;
					break;
				case "3":
					this.paramTitle = "柜控电源单元";
					this.command = 3;
					break;
				case "4":
					this.paramTitle = "整流电源单元";
					this.command = 4;
					break;
				case "5":
					this.paramTitle = "充电电源";
					this.command = 7;
					break;
				case "6":
					this.paramTitle = "电池单元";
					this.command = 5;
					break;
			}
			this.dgMessage = this.paramTitle;
			// 进入页面，读取一次
			if (this.command == 0) {
				this.doRead();
			}
		},
		methods: {
			isRefresh(addr) {
				let that = this;
				let index = addr ? Number(addr) - 1 : 0;
				uni.showModal({
					title: "提示",
					content: "确定要查询吗？",
					success(res) {
						if (res.confirm) {
							that.doRead(index);
						}
					},
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import "@/static/css/common.scss";
	@import "../index.scss";

	.param-contents {
		padding: 20rpx;
		background: #ffffff;

		.param-one {
			@include flexLayout(center, flex-start);
			border-bottom: 2rpx solid #e5e5e5;
			font-size: 28rpx;
			color: #333333;
			padding: 10rpx 0;

			text {
				width: 220rpx;
				text-align: right;
				margin-right: 20rpx;
			}
		}

		.operate_btns {
			text-align: center;
			margin: 60rpx 0 20rpx;
		}

		.param-title {
			border-left: 8rpx solid #0081ff;
			padding-left: 12rpx;
			border-radius: 8rpx;
			color: #0081ff;
			font-size: 36rpx;
			font-weight: bold;
			margin: 10rpx 0 40rpx;
		}

		.bin_left {
			margin-bottom: 40rpx;
		}
	}
</style>